<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>fetch</title>
</head>
<body>
<input type="text" onkeydown="keyDown(event)">
<script>

    // 直接在document上进行绑定方法， 不让文件可以被复制
    document.addEventListener('copy', (e) => {
        e.preventDefault()
        alert('no copy!')
    })
    function keyDown(e){
        // e.key是键盘输入的那个值
        // e.keyCode是键盘输入的那个值对应的ASCII值
        console.log(e.key)
        console.log(e.keyCode)
    }
    window.onload = () => {
        // onkeydown()
        // get 方法获取到接口数据
       async function getData() {
            const response = await fetch('http://iwenwiki.com/api/blueberrypai/getIndexBanner.php')
            if(response.ok){
                const res = await response.json()
                console.log(res)
            }
        }
        getData()
    }

    // post推送数据到服务器端
    async function postData() {
        try{
            const response = await fetch('http://iwenwiki.com/api/blueberrypai/getIndexBanner.php',{
                method: 'post',
                headers: {
                    'content-type':'application/json',
                    'cache-control': 'no-cache'
                },
                body: JSON.stringify({name: 'ck'})
            })
            if(response.ok){
                const res = await response.json()
                console.log(res)
            }
        }catch (e) {
            console.log(e)
        }
    }
</script>
</body>
</html>
